package com.wc.alorithm_luogu._动态规划._数位DP.P4999_烦人的数学作业;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/18 17:12
 * @description https://www.luogu.com.cn/problem/P4999
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 20;
    static int P = (int) 1e9 + 7;
    // f[i][j]表示从左往右第i位为和为sum的时候的
    static int[][] f = new int[N][N * 9 + 10];
    static int[] num = new int[N];
    static int t;
    static long l, r;

    public static void main(String[] args) {

    }

    /**
     * @param pos   当前到第几位了
     * @param s     上面位置的数
     * @param limit 是否有限制
     * @param lead  前导0限制
     * @return
     */
    static int dfs(int pos, int s, int sum, boolean lead, boolean limit) {
        if (pos == 0) return 0;
        if (!limit && !lead && f[pos][s] != -1) return f[pos][s];
        int up = limit ? num[pos] : 9;
        int res = 0;
        for (int i = 0; i <= up; i++) {
            if (lead && i == 0) {
                res = 0;
            }
            res += dfs(pos - 1, i, sum + i, true, limit && i == num[pos]);
        }

        if (!limit && !lead) f[pos][s] = res;
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
